package com.mashibing.class03;

import java.util.HashMap;
import java.util.TreeMap;

/**
 * @Auther: huangxiaode
 * @Date: 2024-01-30 - 01 - 30 - 19:20
 * @Description: com.mashibing.class03
 * @version: 1.0
 */
public class Code05_HashMapTreeMap {

    public static class Node{
        public int value;

        public Node(int val){
            value = val;
        }
    }

    public static void main(String[] args) {
        HashMap<String,String> map = new HashMap<String, String>();
        map.put("zuochenyun","我是左程云");
        System.out.println(map.containsKey("zuochenyun"));
        System.out.println(map.containsKey("zuo"));
        System.out.println(map.get("zuochenyun"));


        map.put("zuochenyun","他是左程云");
        System.out.println(map.get("zuochenyun"));

//        map.remove("zuochenyun");
//        System.out.println(map.containsKey("zuochenyun"));
//        System.out.println(map.get("zuochenyun"));

        String test1 = "zuochenyun";
        String test2 = "zuochenyun";
        System.out.println(map.containsKey(test1));
        System.out.println(map.containsKey(test2));
        System.out.println("=========================map2======================");
        HashMap<Integer,String> map2 = new HashMap<Integer, String>();
        map2.put(1234567,"我是1234567");
        Integer a = 1234567;
        Integer b = 1234567;
        System.out.println(a == b);
        System.out.println(a.equals(b));
        //Integer Double Float String Char
        System.out.println(map2.containsKey(a));
        System.out.println(map2.containsKey(b));
        System.out.println("======================map3===========================");
        Node node1 = new Node(1);
        Node node2 = new Node(2);
        HashMap<Node,String> map3 = new HashMap<Node, String>();
        map3.put(node1,"我进来了!!!");
        System.out.println(map3.containsKey(node1));
        System.out.println(map3.containsKey(node2));
        System.out.println("==================treemap========================");
        TreeMap<Integer,String> treeMap1 = new TreeMap<Integer, String>();
        treeMap1.put(3,"我是3");
        treeMap1.put(0,"我是3");
        treeMap1.put(7,"我是3");
        treeMap1.put(2,"我是3");
        treeMap1.put(5,"我是3");
        treeMap1.put(9,"我是3");
        System.out.println(treeMap1.containsKey(7));
        System.out.println(treeMap1.containsKey(6));
        System.out.println(treeMap1.get(3));
        treeMap1.put(3,"他是3");
        System.out.println(treeMap1.get(3));
        treeMap1.remove(3);
        System.out.println(treeMap1.get(3));

        System.out.println(treeMap1.firstKey());
        System.out.println(treeMap1.lastKey());

        //<=5 离5最近的key告诉我
        System.out.println(treeMap1.floorKey(5));
        //<=6 离6最近的key告诉我
        System.out.println(treeMap1.floorKey(5));
        //>=5 离5最近的key告诉我
        System.out.println(treeMap1.ceilingKey(5));
        //>=6 离6最近的key告诉我
        System.out.println(treeMap1.ceilingKey(6));


        Node node3 = new Node(3);
        Node node4 = new Node(4);
        TreeMap<Node,String> treeMap2 = new TreeMap<Node, String>();
        treeMap2.put(node3,"我是node3");
        treeMap2.put(node4,"我是node4");
    }

}
